﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using AppTouchScreen.Model;
using AppTouchScreen.ViewModels;

namespace AppTouchScreen.Views
{
    /// <summary>
    /// Логика взаимодействия для ProductDataView.xaml
    /// </summary>
    public partial class ProductDataView : UserControl
    {

        public ProductDataView()
        {
            InitializeComponent();
        }

        private void BaginAnimation(object o, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "SelectedCover")
            {
                //animation image
                var daImg = new DoubleAnimation();
                daImg.From = 0.2;
                daImg.To = 1;
                daImg.Duration = new Duration(TimeSpan.FromSeconds(0.5));
                imgMain.BeginAnimation(Image.OpacityProperty, daImg);

                //animation for two grids
                var daGrd = new DoubleAnimation();
                daGrd.From = 0.1;
                daGrd.To = 1;
                daGrd.Duration = new Duration(TimeSpan.FromSeconds(0.5));
                daGrd.EasingFunction = new CircleEase();
                daGrd.EasingFunction.Ease(3);
                var st = new ScaleTransform();
                grdTopText.RenderTransform = st;
                grdBottomText.RenderTransform = st;
                st.BeginAnimation(ScaleTransform.ScaleYProperty, daGrd);
            }

        }

        private void pdv_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (this.DataContext is MainWindowViewModel)
            {
                var dc = this.DataContext as MainWindowViewModel;
                dc.PropertyChanged += BaginAnimation;
            }
        }


    }
}
